<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自动加载进度条</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        
        .progress-container {
            width: 300px;
            background-color: #ddd;
            border-radius: 5px;
            overflow: hidden;
        }
        
        .progress-bar {
            width: 0;
            height: 20px;
            background-color: #4caf50;
            text-align: center;
            line-height: 20px;
            color: white;
            transition: width 0.1s ease-in-out;
        }
    </style>
</head>

<body>
    <div class="progress-container">
        <div class="progress-bar" id="progressBar">0%</div>
    </div>

    <script>
        // 设置进度条的总时间（毫秒）
        const totalTime = 5000; // 5秒
        const progressBar = document.getElementById('progressBar');

        let start = null;

        function step(timestamp) {
            if (!start) start = timestamp;
            const progress = Math.min((timestamp - start) / totalTime, 1);
            progressBar.style.width = `${progress * 100}%`;
            progressBar.textContent = `${Math.round(progress * 100)}%`;
            if (progress < 1) {
                requestAnimationFrame(step);
            }
        }

        requestAnimationFrame(step);
    </script>
</body>

</html>